#ifndef WINDY_NEWDOC_HPP
#define WINDY_NEWDOC_HPP

#include <wx/wxprec.h>

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

#include "constants.hpp"
//#include "monkey_prefs.hpp"

#include <wx/spinctrl.h>

/**
* Implements the about dialog box, which displays information about the program.
* ie: version, build, license, author(s).
*/
class WindyNewDocDialog : public wxDialog
{
public:
   WindyNewDocDialog (wxWindow *parent, const wxString &title/*, MonkeyPrefs &pref*/, const wxSize &size = wxDefaultSize) :
   wxDialog(parent, wxID_ANY, title, wxDefaultPosition, size)/*, prefs(pref)*/
   {
      wxBoxSizer *docname_sz = new wxBoxSizer(wxHORIZONTAL);
      wxStaticText *namelbl = new wxStaticText(this, wxID_ANY, _("Name"));
      wxTextCtrl *nametxt = new wxTextCtrl(this, WindyNewDoc_Name);
      docname_sz->Add(namelbl, wxSizerFlags().Border(wxTOP, 4));
      docname_sz->Add(nametxt, wxSizerFlags(1).Expand().Border(wxLEFT, 5));

      wxBoxSizer *grid_sz = new wxBoxSizer(wxHORIZONTAL);
      wxStaticText *gridlbl = new wxStaticText(this, wxID_ANY, _("Size"));
      wxSpinCtrl *gridwidth = new wxSpinCtrl(this, WindyNewDoc_GridWidth, wxEmptyString, wxDefaultPosition, wxSize(50, 20));
      wxStaticText *gridxlbl = new wxStaticText(this, wxID_ANY, _("x"));
      wxSpinCtrl *gridheight = new wxSpinCtrl(this, WindyNewDoc_GridHeight, wxEmptyString, wxDefaultPosition, wxSize(50, 20));
      grid_sz->Add(gridlbl, wxSizerFlags().Border(wxTOP, 4));
      grid_sz->Add(gridwidth, wxSizerFlags().Border(wxLEFT, 5));
      grid_sz->Add(gridxlbl, wxSizerFlags().Border(wxRIGHT | wxLEFT, 3));
      grid_sz->Add(gridheight, wxSizerFlags());

      gridwidth->SetRange(2, 64);
      gridheight->SetRange(2, 64);

      wxBoxSizer *buttons_sz = new wxBoxSizer(wxHORIZONTAL);
      wxButton *btnok = new wxButton(this, wxID_OK, _("Ok"));
      wxButton *btncancel = new wxButton(this, wxID_CANCEL, _("Cancel"));
      buttons_sz->AddStretchSpacer(1);
      buttons_sz->Add(btnok, wxSizerFlags().Right().Border(wxRIGHT, 5));
      buttons_sz->Add(btncancel, wxSizerFlags().Right());

      wxBoxSizer *global_sz = new wxBoxSizer(wxVERTICAL);
      global_sz->Add(docname_sz, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT | wxTOP, 10));
      global_sz->AddSpacer(5);
      global_sz->Add(grid_sz, wxSizerFlags().Border(wxLEFT | wxRIGHT, 10));
      global_sz->AddStretchSpacer(1);
      global_sz->Add(buttons_sz, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT | wxBOTTOM, 10));

      SetSizer(global_sz);

      /*
      always_center->SetValue(prefs.getBool(wxT("window-centered")));
      remember_size->SetValue(prefs.getBool(wxT("remember-size")));
      remember_pos->SetValue(prefs.getBool(wxT("remember-position")));
      remember_ui->SetValue(prefs.getBool(wxT("remember-ui-state")));

      prvw_width->SetValue(prefs.get(wxT("preview-width")));
      prefs.getBool(wxT("results-offset-mode"), wxT("hex")) ? off_hex->SetValue(true) : off_dec->SetValue(true);

      sb_size->SetValue(wxString::Format(wxT("%d"), prefs.getInt(wxT("search-buffer-size")) / 1048576));
      */
   }

   ~WindyNewDocDialog () {
   }

   void OnOk (wxCommandEvent &event)
   {
      /*
      prefs.setBool(wxT("window-centered"), dynamic_cast <wxCheckBox *> (FindWindowById(MonkeyOptions_AlwaysCenter))->GetValue());
      prefs.setBool(wxT("remember-size"), dynamic_cast <wxCheckBox *> (FindWindowById(MonkeyOptions_RememberSize))->GetValue());
      prefs.setBool(wxT("remember-position"), dynamic_cast <wxCheckBox *> (FindWindowById(MonkeyOptions_RememberPos))->GetValue());
      prefs.setBool(wxT("remember-ui-state"), dynamic_cast <wxCheckBox *> (FindWindowById(MonkeyOptions_RememberUI))->GetValue());

      wxRadioButton *hex_offset = dynamic_cast <wxRadioButton *> (FindWindowById(MonkeyOptions_OffsetHex));
      prefs.set(wxT("results-offset-mode"), hex_offset->GetValue() ? wxT("hex") : wxT("dec"));

      wxSpinCtrl *sb_size = dynamic_cast <wxSpinCtrl *> (FindWindowById(MonkeyOptions_SearchBuffer));
      prefs.setInt(wxT("search-buffer-size"), sb_size->GetValue() * 1048576);

      wxSpinCtrl *prvw_width = dynamic_cast <wxSpinCtrl *> (FindWindowById(MonkeyOptions_PreviewWidth));
      prefs.setInt(wxT("preview-width"), prvw_width->GetValue());*/

      
      EndModal(event.GetId());
   }

   wxSize GetGridSize() const
   {
      int w = dynamic_cast <wxSpinCtrl *> (FindWindowById(WindyNewDoc_GridWidth))->GetValue();
      int h = dynamic_cast <wxSpinCtrl *> (FindWindowById(WindyNewDoc_GridHeight))->GetValue();

      return wxSize(w, h);
   }

   wxString GetDocName() const {
      return dynamic_cast <wxTextCtrl *> (FindWindowById(WindyNewDoc_Name))->GetValue();
   }

private:
   //MonkeyPrefs &prefs;

   DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(WindyNewDocDialog, wxDialog)
   EVT_BUTTON(wxID_OK, WindyNewDocDialog::OnOk)
END_EVENT_TABLE()

#endif //~WINDY_NEWDOC_HPP